package com.ev.k3cloudBusiness.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.utils.R;
import com.ev.k3cloud.vo.IdsVo;
import com.ev.k3cloudBusiness.service.K3StkInStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "/", tags = "金蝶K3Cloud采购入库")
@RestController
public class K3StkInStockController {
    @Autowired
    K3StkInStockService k3StkInStockService;
    @EvApiByToken(value = "/apis/stkInStock/submitStkInStockByIds", method = RequestMethod.POST, apiTitle = "根据内码提交入库单")
    @ApiOperation("根据内码提交入库单")
    public R submitStkInStockByIds(@RequestBody @Param("ids") IdsVo ids) {
        try {
            String result = k3StkInStockService.submitStkInStockByIds(ids.getIds());
            JSONObject resultObj = JSON.parseObject(result);
            if( resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getBooleanValue("IsSuccess") ) {
                return R.ok();
            } else {
                return R.error(resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getJSONArray("Errors").toString());
            }
        }
        catch (Exception ex) {
            return R.error(ex.getMessage());
        }
    }
    @EvApiByToken(value = "/apis/stkInStock/auditStkInStockByIds", method = RequestMethod.POST, apiTitle = "根据内码审核入库单")
    @ApiOperation("根据内码审核入库单")
    public R auditStkInStockByIds(@RequestBody @Param("ids") IdsVo ids) {
        try {
            String result = k3StkInStockService.auditStkInStockByIds(ids.getIds());
            JSONObject resultObj = JSON.parseObject(result);
            if( resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getBooleanValue("IsSuccess") ) {
                return R.ok();
            } else {
                return R.error(resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getJSONArray("Errors").toString());
            }
        }
        catch (Exception ex) {
            return R.error(ex.getMessage());
        }
    }
    @EvApiByToken(value = "/apis/stkInStock/unauditStkInStockByIds", method = RequestMethod.POST, apiTitle = "根据内码反审核入库单")
    @ApiOperation("根据内码反审核入库单")
    public R unauditStkInStockByIds(@RequestBody @Param("ids") IdsVo ids) {
        try {
            String result = k3StkInStockService.unauditStkInStockByIds(ids.getIds());
            JSONObject resultObj = JSON.parseObject(result);
            if( resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getBooleanValue("IsSuccess") ) {
                return R.ok();
            } else {
                return R.error(resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getJSONArray("Errors").toString());
            }
        }
        catch (Exception ex) {
            return R.error(ex.getMessage());
        }
    }
    @EvApiByToken(value = "/apis/stkInStock/deleteStkInStockByIds", method = RequestMethod.POST, apiTitle = "根据内码删除入库单")
    @ApiOperation("根据内码删除入库单")
    public R deleteStkInStockByIds(@RequestBody @Param("ids") IdsVo ids) {
        try {
            String result = k3StkInStockService.deleteStkInStockByIds(ids.getIds());
            JSONObject resultObj = JSON.parseObject(result);
            if( resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getBooleanValue("IsSuccess") ) {
                return R.ok();
            } else {
                return R.error(resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getJSONArray("Errors").toString());
            }
        }
        catch (Exception ex) {
            return R.error(ex.getMessage());
        }
    }
}
